<?php
class Solicitudes_Form_Docentes extends Form_Cna {

    public function __construct($options = null) {
        parent::__construct($options);
    }

    public function init() {
        $domConfig = Zend_Registry::get('domConfig'); //esto se crea en el bootstrap
        $this->setName('instalaciones');
        $this->setMethod("post");
        $this->setAttrib('enctype', 'multipart/form-data');
        
        $codtab = new Zend_Form_Element_Hidden("codtab");
        $codboton = new Zend_Form_Element_Hidden("codboton");
        $codboton2 = new Zend_Form_Element_Hidden("codboton2");
        $array_elements[] = $codtab;
        $array_elements[] = $codboton;
        $array_elements[] = $codboton2;
        $array_elements[] = new Zend_Form_Element_Hidden("codseccionlista");
        
        $array_dedicacion = $domConfig->TIPO_DEDICACION->toArray();
        $array_nivel = $domConfig->TIPO_NIVEL->toArray();
        
        $element = new Zend_Form_Element_Text("ano"); //año
        $element->addFilter('StripTags');
        $element->addFilter('StringTrim');
        $element->addValidator('digits');
        $element->setAttrib("size", 6);
        $element->setRequired(true);
        $element->addValidator(new Zend_Validate_Between(1900,date("Y")));
        $array_elements[] = $element;

        $element = new Zend_Form_Element_Text("periodo"); //periodo
        $element->addFilter('StripTags');
        $element->addFilter('StringTrim');
        $element->addValidator('digits');
        $element->setAttrib("size", 1);
        $element->setRequired(true);
        $element->addValidator(new Zend_Validate_Between(1,2));
        $array_elements[] = $element;
        
//        $capturar = true;
        for ($index1 = 1; $index1 < 6; $index1++) { //años
            for ($index2 = 2; $index2 > 0; $index2--) { // periodos
	            
                $element = new Zend_Form_Element_Text("ano_{$index1}_{$index2}"); //año
		        $element->addFilter('StripTags');
		        $element->addFilter('StringTrim');
		        $element->addValidator('digits');
		        $element->setAttrib("size", 6);
		        $element->setOptions(array('readOnly'=>true));
		        $array_elements[] = $element;

	            $element = new Zend_Form_Element_Text("periodo_{$index1}_{$index2}"); //periodo
		        $element->addFilter('StripTags');
		        $element->addFilter('StringTrim');
		        $element->addValidator('digits');
		        $element->setAttrib("size", 1);
		        $element->addValidator(new Zend_Validate_Between(1,2));
		        $element->setOptions(array('readOnly'=>true));
		        
		        $array_elements[] = $element;
                
                foreach($array_dedicacion as $keyd => $valued) {  // dedicación
                    foreach($array_nivel as $keyn => $valuen) { // nivel de formación
	                    $element = new Zend_Form_Element_Text("cantidad_{$index1}_{$index2}_{$keyd}_{$keyn}");
		                $element->addFilter('StripTags');
		                $element->addFilter('StringTrim');
		                $element->addValidator('digits');
		                $element->setAttrib("size", 7);
		                $array_elements[] = $element;
                    }
	                $element = new Zend_Form_Element_Text("total_{$index1}_{$index2}_{$keyd}");
		            $element->addFilter('StripTags');
		            $element->addFilter('StringTrim');
		            $element->addValidator('digits');
		            $element->setAttrib("size", 7);
		            $element->helper = "formNote";
		            $array_elements[] = $element;
                }
            }
        }
        
       $submit = new Zend_Form_Element_Submit('btnSubmit');
       $submit->setValue('Guardar');
       $submit->setLabel("Guardar");
       $submit->setAttrib("class", "iceCmdBtn");
       $array_elements[] = $submit;
       
       $this->addElements($array_elements);
       $this->loadViewScriptDecorators();
       //$this->loadTableDecorators();
    
    }

    public function loadViewScriptDecorators() {
        $this->setDecorators(array(array('viewScript',array('viewScript'=>'viewscripts/docentes_form.phtml'))));
    }
}